#include <iostream>
//if C++20 deinfe __cpp_lib_endian
#if __cpp_lib_endian >= 201907L && __has_include(<bit>)
#include <bit>
#endif

void check_endianness() {
#if __cpp_lib_endian >= 201907L && __has_include(<bit>)
    std::cout << "bit header is available" << std::endl;
    if constexpr (std::endian::native == std::endian::little) {
        std::cout << "系统是小端字节序 (Little Endian)" << std::endl;
    } else if constexpr (std::endian::native == std::endian::big) {
        std::cout << "系统是大端字节序 (Big Endian)" << std::endl;
    } else {
        std::cout << "系统是混合字节序 (Mixed Endian)" << std::endl;
    }
#else
    std::cout << "bit header is not available" << std::endl;
    unsigned int num = 1;
    if (*(char *)&num == 1) {
        std::cout << "系统是小端字节序 (Little Endian)" << std::endl;
    } else {
        std::cout << "系统是大端字节序 (Big Endian)" << std::endl;
    }
#endif
}

int main() {
    check_endianness();
    return 0;
}